package com.google.code.sysarch.v4.vrml_loader;

public class VRML_Version2 implements VRML_Definitions {

	private final static String[][] blocks = {{
		"_default",
			"{",				"begin",
			"}",				"return",
			"[",				"begin",
			"]",				"return",
			"NULL",				"return",
			"DEF",				"Definition",
			"USE",				"Use",
	},{			
		"_root",
			"CoordinateInterpolator",	"CoordinateInterpolator",		
			"Transform",				"Transform",
			"Group",					"Group",
			"Shape",					"Shape",
			"Viewpoint",				"Viewpoint",
	},{
		"_unknown",			
	},{
		"Appearance",
			"material", 		"Material",
			"texture",			"ImageTexture",
	},{
		"Background",
			"skyColor",			"pointlist",
	},{
		"Children",
			"Shape",			"Shape",
			"Transform",		"Transform",
			"Group",			"Group",
	},{
		"Coordinate",
			"point",			"pointlist",
	},{
		"CoordinateInterpolator",
			"key",				"pointlist",
			"keyValue",			"pointlist",
	},{
		"Group",
			"children",			"Children"
	},{		
		"ImageTexture",
			"url",				"String",
			"repeatS",			"boolean",
			"repeatT",			"boolean",
	},{
		"IndexedFaceSet",
			"ccw",				"boolean",
			"creaseAngle",		"float",
			"coord",			"Coordinate",
			"coordIndex",		"intlist",			
			"solid",			"boolean",
			"texCoord",			"TextureCoordinate",
			"texCoordIndex",	"intlist",
	},{
		"Material",
			"ambientIntensity",	"float",
			"diffuseColor",		"float[3]",
			"emissiveColor",	"float[3]",
			"shininess",		"float",
			"specularColor",	"float[3]",			
			"transparency",		"float",
	},{
		"Normal",
			"vector",			"float[3]",
	},{
		"Script",			
	},{		
		"Shape",
			"appearance",		"Appearance",
			"geometry",			"IndexedFaceSet",
	},{			
		"TextureCoordinate",
			"point",			"pointlist",
	},{
		"TimeSensor",
	},{
		"TouchSensor",
	},{
		"Transform",
			"center",			"float[3]",
			"children",			"Children",			
			"rotation",			"float[4]",
			"scale",			"float[3]",
			"scaleOrientation",	"float[4]",
			"translation",		"float[3]",
	},{
		"Viewpoint",
			"position",			"float[3]",
			"orientation",		"float[4]",
			"fieldOfView",		"float",
			"description",		"String",
	}};

	
	public VRML_Version2() {
		
	}

	public boolean expected(String attribute, String block) {
		for (int i=0; i<blocks.length; i++) {
			if (blocks[i][0].equals(block) || blocks[i][0].equals("_default")) {
				for (int j=1; j<blocks[i].length; j+=2) {
					if (blocks[i][j].equals(attribute)) {
						return true;
					}
				}
				if (blocks[i][0].equals(block)) return false;
			}
		}
		return false;
	}

	public String type(String attribute, String block) {
		for (int i=0; i<blocks.length; i++) {
			if (blocks[i][0].equals(block) || blocks[i][0].equals("_default")) {
				for (int j=1; j<blocks[i].length; j+=2) {
					if (blocks[i][j].equals(attribute)) {
						return blocks[i][j+1];
					}
				}
				if (blocks[i][0].equals(block)) return null;
			}
		}		
		return null;
	}

	public String[] getDefault(String attribute, String blocktype) {
		if (attribute.equals("rotation")) {
			String[] result = { "float[4]", "0", "0", "0", "0" };
			return result;			
		} else if (attribute.equals("scale")) {
			String[] result = { "float[3]", "1", "1", "1" };
			return result;			
		} else if (attribute.equals("translation")) {
			String[] result = { "float[3]", "0", "0", "0" };
			return result;			
		}
		return null;
	}
	
}
